<!-- 优惠券详情 -->
<template>
  <div class="app-container" id='CouponDetail'>
    <div class="table-layout">
      <el-row>
        <el-col :span="4" class="table-cell-title">名称</el-col>
        <el-col :span="4" class="table-cell-title">介绍名称</el-col>
        <el-col :span="4" class="table-cell-title">标签</el-col>
        <el-col :span="4" class="table-cell-title">优惠券类型</el-col>
        <el-col :span="4" class="table-cell-title">最低消费</el-col>
        <el-col :span="4" class="table-cell-title">优惠面值</el-col>
      </el-row>
      <el-row>
        <el-col :span="4" class="table-cell">{{ coupon.name }}</el-col>
        <el-col :span="4" class="table-cell">{{ coupon.desc }}</el-col>
        <el-col :span="4" class="table-cell">{{ coupon.tag }}</el-col>
        <el-col :span="4" class="table-cell">{{ coupon.type }}</el-col>
        <el-col :span="4" class="table-cell">满{{ coupon.min }}元可用</el-col>
        <el-col :span="4" class="table-cell">减免{{ coupon.discount }}元</el-col>
      </el-row>
      <el-row>
        <el-col :span="4" class="table-cell-title">每人限额</el-col>
        <el-col :span="4" class="table-cell-title">当前状态</el-col>
        <el-col :span="4" class="table-cell-title">商品范围</el-col>
        <el-col :span="4" class="table-cell-title">有效期</el-col>
        <el-col :span="4" class="table-cell-title">优惠兑换码</el-col>
        <el-col :span="4" class="table-cell-title">发行数量</el-col>
      </el-row>
      <el-row>
        <el-col :span="4" class="table-cell">{{ coupon.limit }}</el-col>
        <el-col :span="4" class="table-cell">{{ coupon.status }}</el-col>
        <el-col :span="4" class="table-cell">{{ coupon.goodsType }}</el-col>
        <el-col :span="4" class="table-cell">{{ coupon.timeType }}</el-col>
        <el-col :span="4" class="table-cell">{{ coupon.code }}</el-col>
        <el-col :span="4" class="table-cell">{{ coupon.total }}</el-col>
      </el-row>
    </div>

    <div class="filter-container" style="float:right;margin-top:10px">
      <el-input v-model="listQuery.userId" clearable class="filter-item" style="width:200px" placeholder="请输入用户id">
      </el-input>
      <el-select v-model="listQuery.status" clearable class="filter-item" style="width:200px" placeholder="请选择使用状态">
        <el-option v-for="type in useStatusOptions" :key="type.value" :label="type.label" :value="type.value">
        </el-option>
      </el-select>
      <el-button type="primary" class="filter-item" icon="el-icon-search" @click="handleFilter">查询</el-button>
    </div>
    <el-table :data="tableData" style="width: 100%" border fit highlight-current-row>
      <el-table-column prop="id" align="center" label="用户优惠券ID" sortable width="120">
      </el-table-column>
      <el-table-column prop="userId" align="center" label="用户ID" width="180">
      </el-table-column>
      <el-table-column prop="addTime" align="center" label="领取时间">
      </el-table-column>
      <el-table-column prop="status" align="center" label="使用状态">
      </el-table-column>
      <el-table-column prop="orderId" align="center" label="订单ID">
      </el-table-column>
      <el-table-column prop="usedTime" align="center" label="使用时间">
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      @pagination="getList" />
  </div>
</template>
<script >
import Pagination from '@/components/Pagination'
import { readCoupon, listCouponUser } from '@/api/activity/coupon'
const useStatusOptions = [{
  label: '未使用',
  value: 0
},
{
  label: '已使用',
  value: 1
},
{
  label: '已过期',
  value: 2
},
{
  label: '已下架',
  value: 3
}]
export default {
  name: 'CouponDetail',
  data() {
    return {
      useStatusOptions,
      coupon: {},
      listQuery: {
        page: 1,
        limit: 10,
        couponId: 0,
        userId: '',
        status: '',
      },
      tableData: [],
      total: 0
    }
  },
  props: [],
  components: {
    Pagination
  },
  created() {
    this.init();
  },
  mounted() {
  },
  methods: {
    //获取优惠券详情
    init: function () {
      //判断上个页面是否有传id
      if (this.$route.query.id == null) {
        return
      }
      readCoupon(this.$route.query.id).then(response => {
        this.coupon = response.data.data;
      })
      this.listQuery.couponId = this.$route.query.id;
      this.getList();
    },
    //获取用户优惠券列表
    getList() {
      listCouponUser(this.listQuery).then(res => {
        this.tableData = res.data.data.list;
        this.total = res.data.data.total;
      })
    },
    //筛选列表信息
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
  }
};
</script>
<style lang='scss'>
.table-layout {
  border-left: 1px solid #DCDFE6;
  border-top: 1px solid #DCDFE6;
  margin-top: 20px;
}

.table-cell-title {
  border-right: 1px solid #DCDFE6;
  border-bottom: 1px solid #DCDFE6;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  background: #f2f6fc;
  color: #303133;
}

.table-cell {
  height: 60px;
  line-height: 40px;
  border-right: 1px solid #DCDFE6;
  border-bottom: 1px solid #DCDFE6;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  color: #606266;
}

// .search-item{
//       width: 200px;
//       margin-right: 5px;
//     }
</style>